# You may, but are NOT required to, use object-oriented programming (OOP) in your solution.
# If you choose to use OOP, the methods described below should be class instance methods.

# You may put any variables that you wish to maintain at the module level:
#The default projected number of hunters is 0.
projected_number_of_hunters = 0
#The default projected rep threshold is .70.
projected_reputation_threshold = .70
#The default project hunt threshold is .60.
projected_hunt_threshold = .60

class Player():
	# Other auxiliary functions are allowed, but your script must implement at least the three
	# functions below, no matter what approach you choose to use. For the OOP option, don't
	# forget to add 'self' as a first argument of every function.

	def hunt_choices(self, round_number, current_food, current_reputation, m,  player_reputations):
    	# The main routine that plays each individual round.
    	# You must create an array of variables 'hunt_decisions' and assign an 'h' for hunt or
    	# an 's' for slack (i.e., not hunt) to each member of the array; the order of the hunt
    	# decisions in hunt_decisions should correspond to the order of opponents'
    	# reputations in player_reputations.

    	# Blank variables or errors will be assigned 's'.

    	# The variables passed in to hunt_choices for your use are:
    	#     round_number: integer, the number round you are in.
    	#     current_food: integer, the amount of food you have.
    	#     current_reputation: float (python's representation of real numbers), your current reputation.
    	#     m: integer, the threshold cooperation/hunting value for this round.
    	#     player_reputations: list of floats, the reputations of all the remaining players in the game.
    	#                         The ordinal positions of players in this list will be randomized each round.

    	# You may use the global syntax to assign values to any global variables you define, as in:
		#Calculate chance of all players being hunters for a round and get the number of project hunters. Also get the total number of players.
		hunt_decisions = []
		coop_reward = 0
		global projected_number_of_hunters
		global projected_hunt_threshold
		projected_number_of_hunters = 0
		total_number_of_players = len(player_reputations)
		for rep in player_reputations:
			#If their reputation is over the projected_reputation_threshold assumed they will hunt this round.
			if (rep >= projected_reputation_threshold):
				projected_number_of_hunters += 1
		#If the projected number of hunters is greater than m, then we assume we will get the 2(P - 1) reward this round.
		if (projected_number_of_hunters + 1 > m):
			coop_reward = 2 * (total_number_of_players - 1)
	
		for rep in player_reputations:
			#If theres a good chance of getting the coop reward, risk it and hunt. This also helps combat a tie with someone who always just picks slack.
			if (coop_reward >= 3):
				hunt_decisions.append('h')
			#If theres a decent chance of the current foe hunting with you, choose slack.
			elif (rep >= projected_hunt_threshold):
				hunt_decisions.append('s')
			#Otherwise just slack.
			else:
				hunt_decisions.append('s')
		return hunt_decisions;

	def hunt_outcomes(self, food_earnings):
    	# hunt_outcomes is called after all hunts for the round are complete.

    	# Add any code you wish to modify your variables based on the outcome of the last round.

    	# The variable passed in to hunt_outcomes for your use is:
    	#     food_earnings: list of integers, the amount of food earned from the last round's hunts.
    	#                    The entries can be negative as it is possible to lose food from a hunt.
    	#                    The amount of food you have for the next round will be current_food
    	#                    + sum of all entries of food_earnings.
    	#                    The list will be in the same order as the decisions you made in that round.
		global projected_hunt_threshold
		number_of_hunts = 0
		number_of_fails = 0
		#Checks and adjust's my hunt threshold if the choice to hunt was wrong for a majority of the round (aka I get -3 food earned). 
		for value in food_earnings:
			if (value == -3):
				number_of_hunts += 1
				number_of_fails += 1
			elif (value == 0):
				number_of_hunts += 1
		#If my projection is too high, adjust it by a little bit.
		if (number_of_hunts > 0 and (number_of_fails / number_of_hunts) >= .50):
			projected_hunt_threshold -= .05

	def round_end(self, award, m, number_hunters):
    	# round_end is called after all hunts for the round are complete.

    	# award - the total amount of food you received due to cooperation in the round.
    	# Can be zero if the threshold m was not reached.

    	# Add any code you wish to modify your variables based on the cooperation that occurred in
    	# the last round.

    	# The variables passed in to round_end for your use are:
    	#     award: integer, total food bonus (can be zero) you received due to players cooperating
    	#            during the last round. The amount of food you have for the next round will be
    	#            current_food (including food_earnings from hunt_outcomes this round) + award.
    	#     number_hunters: integer, number of times players chose to hunt in the last round.
		#If my prediction is off by more than 10% adjust the projected reputation threshold.
		global projected_reputation_threshold
		if (projected_number_of_hunters > (number_hunters + (number_hunters * .10)) or projected_number_of_hunters < (number_hunters - (number_hunters * .10))):
			if (projected_number_of_hunters > (number_hunters + (number_hunters * .10)) and projected_reputation_threshold >= .05):
				projected_reputation_threshold -= .05
			else:
				projected_reputation_threshold += .05